package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedicalBaseUserScheduler;
import com.ruoyi.system.service.IMedicalBaseUserSchedulerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员休息记录Controller
 * 
 * @author ruoyi
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/system/scheduler")
public class MedicalBaseUserSchedulerController extends BaseController
{
    @Autowired
    private IMedicalBaseUserSchedulerService medicalBaseUserSchedulerService;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询人员休息记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalBaseUserScheduler medicalBaseUserScheduler)
    {
        startPage();
        List<MedicalBaseUserScheduler> list = medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerList(medicalBaseUserScheduler);
        for (MedicalBaseUserScheduler m:list) {
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(m.getUserid() + ""));
            m.setSysUser(sysUser);
            System.out.println(sysUser);
        }

        return getDataTable(list);
    }

    /**
     * 导出人员休息记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:export')")
    @Log(title = "人员休息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalBaseUserScheduler medicalBaseUserScheduler)
    {
        List<MedicalBaseUserScheduler> list = medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerList(medicalBaseUserScheduler);
        ExcelUtil<MedicalBaseUserScheduler> util = new ExcelUtil<MedicalBaseUserScheduler>(MedicalBaseUserScheduler.class);
        util.exportExcel(response, list, "人员休息记录数据");
    }

    /**
     * 获取人员休息记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerById(id));
    }


    /**
     * 新增人员休息记录
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:add')")
    @Log(title = "人员休息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalBaseUserScheduler medicalBaseUserScheduler)
    {
        System.out.println(medicalBaseUserScheduler.getUserid());
        medicalBaseUserScheduler.setId(new Date().getTime()+"");
 //       MedicalBaseUserScheduler medicalBaseUserScheduler1 = medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerdata(medicalBaseUserScheduler);
//
//        if(medicalBaseUserScheduler1!=null){
//            if(medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerById(medicalBaseUserScheduler.getUserid()).getDatedetail().equals(medicalBaseUserScheduler.getDatedetail())&&medicalBaseUserSchedulerService.selectMedicalBaseUserSchedulerById(medicalBaseUserScheduler.getUserid()).getRestdate()==medicalBaseUserScheduler.getRestdate()){
//
//                return toAjax(1);
//            }
//        }
            return toAjax(medicalBaseUserSchedulerService.insertMedicalBaseUserScheduler(medicalBaseUserScheduler));



    }

    /**
     * 修改人员休息记录
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:edit')")
    @Log(title = "人员休息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalBaseUserScheduler medicalBaseUserScheduler)
    {
        return toAjax(medicalBaseUserSchedulerService.updateMedicalBaseUserScheduler(medicalBaseUserScheduler));
    }

    /**
     * 删除人员休息记录
     */
    @PreAuthorize("@ss.hasPermi('system:scheduler:remove')")
    @Log(title = "人员休息记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(medicalBaseUserSchedulerService.deleteMedicalBaseUserSchedulerByIds(ids));
    }
}
